<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>



    <!--{include file='comm/header.tpl'}-->
    <title><!--{if $billPlatform eq 1}-->订单<!--{else}-->澳粒订单<!--{/if}-->打印</title>
    <!--{include file='comm/comm_cal.tpl'}-->
    <!--{include file="comm/comm_multiselect.tpl"}-->
    <script src="/quanliadmin/docroot/js/createreoprt.js"></script>
</head>
<body>

<div class="container">
    
        <div class="comm_content">

            <div class="search-box">
                <div style="position:relative">
                    <form method="post" class="form-inline"  id="search_form" action="/quanliadmin/app/send/orderPrint.pscript?operFlg=2" target="_blank">
                        <table>
                            <tbody>
                            <tr>
                                <td height="27px">
                                    <span>配送日期：<input type="text" class="form-control input-sm" readonly style="width:100px" value="<!--{$currentDate|default:''}-->" name="send_date" id="send_date"></span>
                                    <button type="button" class="btn btn-default btn-sm" onclick="orderPrint.timeClear();">清 空</button>
                                    <span>
                                        配送开始时间：
                                        <select name="send_start_time" id="send_start_time" class="form-control input-sm" style="width:100px;">
                                            <option value="">请选择</option>
                                            <!--{foreach from=$sendStartTime_array key=myId item=star}-->
                                            <!--{if $myId == 0}-->
                                            <option value="<!--{$star.itemName}-->" selected><!--{$star.itemName}--></option>
                                            <!--{/if}-->
                                            <option value="<!--{$star.itemName}-->"><!--{$star.itemName}--></option>
                                            <!--{/foreach}-->

                                        </select>
                                    </span>

                                    <span>
                                        配送结束时间：
                                        <select name="send_start_time_end" id="send_start_time_end" class="form-control input-sm" style="width:100px;">
                                            <option value="">请选择</option>
                                            <!--{foreach from=$sendStartTime_array item=end}-->
                                            <!--{if $end.itemName == $end_time}-->
                                            <option value="<!--{$end.itemName}-->" selected><!--{$end.itemName}--></option>
                                            <!--{/if}-->
                                            <option value="<!--{$end.itemName}-->"><!--{$end.itemName}--></option>
                                            <!--{/foreach}-->
                                        </select>
                                    </span>

                                    <span>
                                       配送城市：<select id="deliver_cityid" name="deliver_cityid" class="form-control input-sm" style="width:110px;">
                                            <option value="" selected="">请选择</option>
                                            　　
                                        </select>
                                    </span>

                                    <span>
                                        配送站：
                                        <select name="distribution_id" id="distribution_id" class="form-control input-sm" style="width:120px;">
                                            <option value="">请选择</option>
                                        </select>
                                    </span>

                                    <span>
                                        配送员：
                                        <select name="distribution_technician_id" id="distribution_technician_id" class="form-control input-sm" style="width:120px;">
                                            <option value="">请选择</option>
                                        </select>
                                    </span>

                                    <span>订单类型：<select id="billType" class="form-control input-sm"  name="billType" style="width:120px;">
                                            <option value="all">全部</option>
                                            <!--{foreach from=$global_array.bill_type item=bill_type_name key=bill_type}-->
                                                <option value="<!--{$bill_type}-->"><!--{$bill_type_name.name}--></option>
                                            <!--{/foreach}-->
                                        </select>
                                    </span>

                                    <input type="hidden" id="bill_type" name="bill_type" value=""/>
                                    <!--{if $billPlatform eq 1}-->
                                        <span>
                                        订单品牌：<select class="form-control input-sm" name="billPlatform">
                                                    <option value="1">自营</option>
                                                    <option value="all">全部</option>
                                                    <option value="2">澳粒</option>
                                                    <option value="3">下午茶</option>
                                            </select>
                                        </span>
                                    <!--{/if}-->
                                    <!--{if $billPlatform eq 2}-->
                                        <input type="text" style="display: none;" id="billPlatform" name="billPlatform" value="<!--{$billPlatform}-->" >
                                    <!--{/if}-->
                                    <span>
                                        发票：<select id="invoice" class="form-control input-sm"  name="invoice" style="width:100px;">
                                            <option value="">请选择</option>
                                            <option value="1">是</option>
                                            <option value="0">否</option>
                                        </select>
                                    </span>

                                    <span>
                                        是否已打印配送单：<select id="print_num" class="form-control input-sm"  name="print_num" style="width:100px;">
                                            <option value="">请选择</option>
                                            <option value="1">是</option>
                                            <option value="0">否</option>
                                        </select>
                                    </span>

                                    <span>
                                        是否已打印配送任务清单：<select id="printTaskList_num" class="form-control input-sm"  name="printTaskList_num" style="width:100px;">
                                            <option value="">请选择</option>
                                            <option value="1">是</option>
                                            <option value="0">否</option>
                                        </select>
                                    </span>

                                    <span>订单编号：<input type="text" class="form-control input-sm" style="width:140px" value="" name="bill_code" id="bill_code"></span>

                                    <span>下单日期：<input type="text" class="form-control input-sm" readonly style="width:105px" value="" name="createDate" id="createDate"></span>

                                    <span><input type="button" onclick="orderPrint.search();" class="btn btn-primary" value="查询"></span>
                                    <span><input type="button" onclick="orderPrint.clear();" class="btn btn-warning" value="重置"></span>
                                    <!--{if $permission_20512}-->
                                    <span><input  value="预览打印"  onclick="orderPrint.printCheck(1);" class="btn btn-default" type="button"></span>
                                    <span><input  value="直接打印"  onclick="orderPrint.printCheck(2);" class="btn btn-default" type="button"></span>
                                    <span><input  value="澳粒订单预览打印"  onclick="orderPrint.ALprintCheck(1);" class="btn btn-default" type="button"></span>
                                    <span><input  value="澳粒订单直接打印"  onclick="orderPrint.ALprintCheck(2);" class="btn btn-default" type="button"></span>
                                    <span><input  value="下午茶订单预览打印"  onclick="orderPrint.DunchprintCheck(1);" class="btn btn-default" type="button"></span>
                                    <span><input  value="下午茶订单直接打印"  onclick="orderPrint.DunchprintCheck(2);" class="btn btn-default" type="button"></span>
                                    <!--{/if}-->
                                    <!--{if $permission_20516}-->
                                    <span><input  value="澳粒订单预览打印"  onclick="orderPrint.ALprintCheck(1);" class="btn btn-default" type="button"></span>
                                    <span><input  value="澳粒订单直接打印"  onclick="orderPrint.ALprintCheck(2);" class="btn btn-default" type="button"></span>
                                    <!--{/if}-->
                                    <span><input  value="预览配送任务清单" onclick="orderPrint.check(1);" class="btn btn-default" type="button"></span>
                                    <span><input  value="打印配送任务清单" onclick="orderPrint.check(2);"  class="btn btn-default" type="button"></span>
                                    
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none;"></table>

        </div>


</div>
<script type="text/javascript">

CreateReport("Report");

$('#send_date').datepicker();
$('#createDate').datepicker();
$('#billType').multiselect();
$('#bill_status').multiselect();

var table_id = <!--{$table_id}-->;

var fixed_json = <!--{$fixed_json}-->;

$("#flex").flexigrid({
    url:"/invokingAjax-backend/send/orderPrint.ajax?operFlg=1",
    dataType: "json",
    colModel : fixed_json,
    <!--{if $edit_permission}-->
    buttons : [
        {name: "全选", bclass: "checkAll", onpress : "E.checkAllList"},
        {separator: true},
        {name: "取消全选", bclass: "cancelCheckAll", onpress : "E.cancelCheckAllList"}
    ],
    <!--{/if}-->
    sortname: "createTime ,send_start_time,distribution_technician_id,print_time",
    sortorder: "desc",
    usepager: true,
    rp: 50,//mod by allen.qiang 20140926   20->50所有配送部操作的页面默认显示50条数据
    useRp: true,
    showTableToggleBtn: true,
    autoload: true,
    onSubmit: function() {
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({params: dt});
        return true;
    },

    //拉伸宽度后触发
    onColResize:function(){

        var last_cid = arguments[0];
        var width = arguments[1];

        E.ajax_get({
            url:'/invokingAjax-backend/system/flexigrid.ajax?operFlg=1',
            data:{
                table_id:table_id,
                last_cid:last_cid,
                width:width
            },
            call:function( o ){ }

        });

    },

    //隐藏后触发
    onToggleCol:function(){

        var cid = arguments[0];
        var hide = arguments[1];

        E.ajax_get({
            url:'/invokingAjax-backend/system/flexigrid.ajax?operFlg=3',
            data:{
                table_id:table_id,
                cid:cid,
                hide:hide
            },
            call:function( o ){ }

        });
    },

    //拖拽后触发
    onDragCol:function(){

        var cid = arguments[0];
        var last_cid = arguments[1];

        E.ajax_get({
            url:'/invokingAjax-backend/system/flexigrid.ajax?operFlg=2',
            data:{
                table_id:table_id,
                cid:cid,
                last_cid:last_cid
            },
            call:function( o ){ }

        });

    }

});

var orderPrint= {

    printArr: new Array(),//打印数组变量定义
    para:'',//打印参数 1、打印预览 2、直接打印
    //头部 按条件查询
    search: function() {

        var billType_values = $("#billType").multiselect("getChecked").map(function(){ return this.value;}).get();
        $('#bill_type').val(billType_values);

        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({params: dt}).flexReload();
    },

    //重置
    clear: function(){
        document.forms['search_form'].reset();
        $('#billType').multiselect("refresh");
        $('#bill_status').multiselect("refresh");
        this.search();
    },

    timeClear: function() {
        $('#send_date').val('');
    },

    //重新加载
    load: function() {
        $("#flex").flexReload();
    },

    //订单详情
    billview: function( bill_no ) {
        window.open('/quanliadmin/app/bill/billSearch.pscript?operFlg=9&bill_no=' + bill_no);
    },

    //获取mcake订单打印的行数
    printCheck:function( para ){
  
        //获取选中的行的行数
        orderPrint.para = para; //打印参数 区分打印预览 与 直接打印
        var selected_count = $('.trSelected',flex).length;
        if (selected_count==0) {
            E.alert("请选择要打印的数据");
            return;
        }

        var tempArr = new Array(); //打印的数据行订单号
        for(var i=0; i<selected_count; i++){
            var templateIDStr = $('.trSelected',flex).eq(i).attr('id');
            var templateIDStr = templateIDStr.substr(3);
            tempArr.push(templateIDStr);
        }
		
        Report.LoadFromURL('/report/FHD.grf?b='+Math.floor(Math.random() * ( 1000 + 1)));


        //判断订单是否是自营订单
        E.ajax_post({
            url: "/invokingAjax-backend/send/orderPrint.ajax?operFlg=7",
            data: {
                printBillNoArr:tempArr
            },
            call:function( res ){
                if(res.code == 200){
                    $.each(tempArr, function(k, v) {

                        Report.LoadDataFromURL('/report/print_order.php?bill_no=' + v);
                        if (para == 1) { //预览
                            Report.PrintPreview(true);
                        } else { //直接打印
                            Report.Print(false);
                        }
                    });

                    if( para == 2 ){ //直接打印改变订单主表状态
                        E.ajax_post({
                            url: "/invokingAjax-backend/send/orderPrint.ajax?operFlg=2",
                            data: {
                                printBillNoArr:tempArr
                            },
                            call: 'orderPrint.callRes'
                        });
                    }
                }else{
                    E.alert( res.message );
                }
            }
        });

    },


    //获取澳粒订单打印的行数
    ALprintCheck:function( para ){
        //获取选中的行的行数
        orderPrint.para = para; //打印参数 区分打印预览 与 直接打印

        var selected_count = $('.trSelected',flex).length;
        if (selected_count==0) {
            E.alert("请选择要打印的数据");
            return;
        }

        var tempArr = new Array(); //打印的数据行订单号
        for(var i=0; i<selected_count; i++){
            var templateIDStr = $('.trSelected',flex).eq(i).attr('id');
            var templateIDStr = templateIDStr.substr(3);
            tempArr.push(templateIDStr);
        }

        Report.LoadFromURL('/report/FHD_Ollie.grf?b='+Math.floor(Math.random() * ( 1000 + 1)));

        //判断订单是否是澳粒订单
        E.ajax_post({
            url: "/invokingAjax-backend/send/orderPrint.ajax?operFlg=5",
            data: {
                printBillNoArr:tempArr
            },
            call:function( res ){
                if(res.code == 200){
                    $.each(tempArr, function(k, v) {

                        Report.LoadDataFromURL('/report/print_order_al.php?bill_no=' + v);
                        if (para == 1) { //预览
                            Report.PrintPreview(true);
                        } else { //直接打印
                            Report.Print(false);
                        }
                    });

                    if( para == 2 ){ //直接打印改变订单主表状态
                        E.ajax_post({
                            url: "/invokingAjax-backend/send/orderPrint.ajax?operFlg=6",
                            data: {
                                printBillNoArr:tempArr
                            },
                            call: 'orderPrint.callRes'
                        });
                    }
                }else{
                    E.alert( res.message );
                }
            }
        });


    },


    //获取下午茶订单打印的行数
    DunchprintCheck:function( para ){
        //获取选中的行的行数
        orderPrint.para = para; //打印参数 区分打印预览 与 直接打印

        var selected_count = $('.trSelected',flex).length;
        if (selected_count==0) {
            E.alert("请选择要打印的数据");
            return;
        }

        var tempArr = new Array(); //打印的数据行订单号
        for(var i=0; i<selected_count; i++){
            var templateIDStr = $('.trSelected',flex).eq(i).attr('id');
            var templateIDStr = templateIDStr.substr(3);
            tempArr.push(templateIDStr);
        }

        Report.LoadFromURL('/report/FHD_DUNCH.grf?b='+Math.floor(Math.random() * ( 1000 + 1)));

        //判断订单是否是下午茶订单
        E.ajax_post({
            url: "/invokingAjax-backend/send/orderPrint.ajax?operFlg=8",
            data: {
                printBillNoArr:tempArr
            },
            call:function( res ){
                if(res.code == 200){
                    $.each(tempArr, function(k, v) {

                        Report.LoadDataFromURL('/report/print_order_dunch.php?bill_no=' + v);
                        if (para == 1) { //预览
                            Report.PrintPreview(true);
                        } else { //直接打印
                            Report.Print(false);
                        }
                    });

                    if( para == 2 ){ //直接打印改变订单主表状态
                        E.ajax_post({
                            url: "/invokingAjax-backend/send/orderPrint.ajax?operFlg=9",
                            data: {
                                printBillNoArr:tempArr
                            },
                            call: 'orderPrint.callRes'
                        });
                    }
                }else{
                    E.alert( res.message );
                }
            }
        });


    },





    //打印成功回调
    callRes:function(o){
        if(o.code != 200){
            E.alert( o.message );
        }else{
            E.alert('打印成功',2);
            orderPrint.load();
        }
    },
	//mod by yim.hu 20141113 打印任务配送清单 --start   
    check:function(para){
        //获取选中的行的行数
        orderPrint.para = para; //打印参数 区分打印预览 与 直接打印
        var selected_count = $('.trSelected',flex).length;
        if (selected_count==0) {
            E.alert("请选择要打印的数据");
            return;
        }

        var tempArr = new Array(); //打印的数据行订单号
        for(var i=0; i<selected_count; i++){
            var templateIDStr = $('.trSelected',flex).eq(i).attr('id');
            var templateIDStr = templateIDStr.substr(3);
            tempArr.push(templateIDStr);
        }

        Report.LoadFromURL('/report/peisong.grf?b='+Math.floor(Math.random() * ( 1000 + 1)));

		
		


           //$.each(tempArr, function(k, v) {
				
                Report.LoadDataFromURL('/report/print_peisong.php?bill_no=' + tempArr);
                if (para == 1) { //预览
                    Report.PrintPreview(true);
                } else { //直接打印
                    Report.Print(false);
                }
          //  });
		
            if( para == 2 ){ //直接打印改变订单主表状态
          
                //改变打印配送任务清单次数
                E.ajax_post({
                    url: "/invokingAjax-backend/send/orderPrint.ajax?operFlg=4",
                    data: {
                        printBillNoArr: tempArr
                    },
                    call: 'orderPrint.callAllRes'
                });
	         }
         
        


    },

	//mod by yim.hu 20141113 打印任务配送清单 --end   
    //打印成功回调
    callAllRes:function(o){

        if(o.code != 200){
            E.alert( o.message );
        }else{
            E.alert('打印配送任务清单成功',2);
            orderPrint.load();
        }
    }

};

$(window).ready(function() {

    $("#deliver_cityid").html("");

    var cityHtml = '<option value="">请选择</option>';

    $.ajax({
        type: "post",
        url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=1",
        dataType: "json",
        data: "",
        success: function( result_obj ) {
            if(result_obj.code == 200){
                var selected = "";
                if(result_obj.data.length == 1){
                    selected = "selected";
                }
                $.each(result_obj.data, function(i,val){
                    cityHtml +='<option value="'+val.id+'" '+selected+'>'+val.name+'</option>';
                });
                $('#deliver_cityid').html(cityHtml);
                $("#deliver_cityid").trigger("change");
            }else{
                E.alert(result_obj.message);
            }
        }
    });


    //点击城市联动获得配送站
    $(document).on('change', '#deliver_cityid', function() {

        $('#distribution_id').html("");
        $('#distribution_technician_id').html('');

        var deliver_cityid = $('#deliver_cityid').children('option:selected').val();
        var distributionHtml = '<option value="">请选择</option>';
        var technicianHtml = '<option value="">请选择</option>';
        $.ajax({
            type: "post",
            url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=2",
            dataType: "json",
            data: {deliver_cityid: deliver_cityid},
            success: function( obj ) {
                if(obj.code ==200 && obj.data != null){
                    var selected = "";
                    if(obj.data.length == 1){
                        selected = "selected";
                    }
                    $.each(obj.data, function(i,val){
                        distributionHtml +='<option value="'+val.distribution_id+'" '+selected+'>'+val.distribution_name+'</option>';
                    });
                    $('#distribution_id').html(distributionHtml);
                    $('#distribution_technician_id').html(technicianHtml);
                }else{
                    distributionHtml += '';
                    $('#distribution_id').html(distributionHtml);
                    $('#distribution_technician_id').html(technicianHtml);
                }
                $("#distribution_id").trigger("change");
            }
        });
    });

    //城市，配送站，配送员联动
    $(document).on('change', '#distribution_id', function() {

        $('#distribution_technician_id').html('');
        var distribution_id = $('#distribution_id').children('option:selected').val();
        var technicianHtml = '<option value="">请选择</option>';
        $.ajax({
            type: "post",
            url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=3",
            dataType: "json",
            data: {distribution_id: distribution_id},
            success: function( o ) {
                if(o.code ==200 && o.data != null){
                    $.each(o.data, function(i,val){
                        technicianHtml +='<option value="'+val.distribution_technician_id+'">'+val.distribution_technician_name+'</option>';
                    });
                    $('#distribution_technician_id').html(technicianHtml);
                }else{
                    technicianHtml += '';
                    $('#distribution_technician_id').html(technicianHtml);
                }
            }
        });
    });

});
</script>

</body>
</html>